<?php
include_once '../../config.php';

/**
 * return array(array('actionName' => 'string',
  	 					'productID'=> 'string',
  	 					'origion_price' => 'double',
  	 					'status'=> 'string(open,close)',
  	 					'timeleft' => 'long',
  	 					'aution_price'=> 'double',
  	 					'current_user_bid'=> 'userID: string',
  	 					'price_per_bid' => 'int'))
 */

if ($_POST ['refresh'] == true) {
	$connection = mysql_connect ( $host, $username, $password ) or die ( $connect_error . mysql_error () );
	mysql_select_db ( $db, $connection ) or die ( $connect_error . mysql_error () );

	$result = @mysql_query ( "select * from auction_view", $connection );
	$arr = array ();
	while ( $row = @mysql_fetch_assoc ( $result ) ) {
		
		$status = "open";
		if (strtotime ( $row ['end_time'] ) < strtotime ( 'now' ))
			$status = "closed";
		if (strtotime ( $row ['start_time'] ) > strtotime ( 'now' ))
			$status = "Not started";
		
		$arr = array_merge ( $arr, array (array ('auctionID' => $row ['auctionID'], 'name' => $row ['name'], 'pro_name' => $row ['pro_name'], 'status' => $status, 'start_time' => $row ['start_time'], 'end_time' => $row ['end_time'], 'price' => ltrim ( $row ['price'], '0' ), 'auction_price' => ltrim ( $row ['auction_price'], '0' ), 'quantity' => $row ['quantity'], 'current_user_bid' => $row ['current_user_bid'], 'price_per_bid' => $row ['price_per_bid'] ) ) );
	}
	mysql_close ( $connection );
	die ( json_encode ( $arr ) );
}
